package hikari.objects3d;

import org.swig.jirr.IMeshSceneNode;
import org.swig.jirr.ISceneManager;
import org.swig.jirr.ISceneNode;
import org.swig.jirr.ITriangleSelector;

/**
 * @author Dmitry
 */
public class BillBoard3dObject extends GeometricObject {
    public BillBoard3dObject(ISceneManager sceneManager) {
        super("BillBoard", true);
        initObject(sceneManager);
    }

    public BillBoard3dObject(String name, ISceneManager sceneManager) {
        super(name);
        initObject(sceneManager);
    }

    public BillBoard3dObject(String name, IMeshSceneNode sceneNode) {
        super(name);
        setMeshSceneNode(sceneNode);
    }

    private void initObject(ISceneManager sceneManager) {
        ISceneNode billboard = createSceneNode(sceneManager);
        setMeshSceneNode(billboard);
    }

    public static ISceneNode createSceneNode(ISceneManager sceneManager) {
        ISceneNode billboardMesh = sceneManager.addBillboardSceneNode(sceneManager.getRootSceneNode());
        ITriangleSelector selector = sceneManager.createTriangleSelectorFromBoundingBox(billboardMesh);
        billboardMesh.setTriangleSelector(selector);
        return billboardMesh;
    }

    @Override
    public String objectType() {
        return "billboard";
    }
}